/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.instructional.example.swing.tester;

import java.util.concurrent.ExecutionException;

import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;

public class SwingWorker_Tester_01 {

    public static void main(final String[] args) throws InterruptedException, ExecutionException {
        System.out.println("TID=" + Thread.currentThread().getId() + " (main)");
        final SwingWorker<String, String> x = new SwingWorker<String, String>() {
            @Override
            protected String doInBackground() throws Exception {
                final long tid = Thread.currentThread().getId();
                System.out.println("");
                System.out.println("TID=" + tid + " doInBackground() isEventDispatchThread=" + SwingUtilities.isEventDispatchThread());
                System.out.println("Long running code goes here.");
                return "";
            }

            @Override
            protected void done() {
                final long tid = Thread.currentThread().getId();
                System.out.println("");
                System.out.println("TID=" + tid + "          done() isEventDispatchThread=" + SwingUtilities.isEventDispatchThread());
                System.out.println("GUI updates/changes go here.");
            }
        };
        x.execute();
        x.get();
    }
}
